<script>
    function goBack() {
	window.location.href = "?modul=gallery&action=gallerys_list";
    }
</script>
<?php

function V_Add_Gallery($arrayData, $mode) {
    include("../fckeditor/fckeditor.php");
    $ulr = "?" . MODUL . "=gallery&" . ACTION . "=" . $mode;
    if ($mode == 'Edit_pic') {
	$strLable = "Cập nhật ảnh";
	$strButton = "Cập nhật";
    } else if ($mode == 'add_pic') {
	$strLable = "Thêm mới ảnh";
	$strButton = "Thêm mới";
    }
    ?>
    <h3><?= $strLable ?></h3>
    <form enctype="multipart/form-data" action="<?= $ulr ?>" method="post" name="frm" onSubmit="return validateForm();">
        <input type="hidden" name="id" id="id" value="<?= $arrayData['id']; ?>"/>
        <table width="950px" cellpadding="5" border="1">
    	<tr style="background-color: #99CCFF">
    	    <th colspan="2">Thông tin ảnh</th>
    	</tr>
    	<tr>
    	    <td width="200px"><strong>Chọn nhóm</strong></td>
    	    <td>
    		<select name="type_id">
    		    <option value="0">---ROOT---</option>
			<? gallerys_type(0, 0, $arrayData['type_id']); ?>
    		</select>
<!--		<select name="type_id[]" multiple="multiple" style="width: 200px;height: 150px">
    		    <option value="0">---ROOT---</option>
			<? gallerys_type(0, 0, $arrayData['type_id']); ?>
    		</select>-->
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Tên ảnh</strong></td>
    	    <td>
    		<input type="text" name="name_pic" id="name_pic" value="<?= $arrayData['name_pic']; ?>"/>
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Ảnh</strong></td>
    	    <td>
		    <?
		    if ($mode == "Edit_pic") {
			if ($arrayData['url_pic'] != "") {
			    ?>
	    		<img width="250px" src="<?= DIR_IMG_SLIDE_GALLERY . $arrayData['url_pic'] ?>"/><br/><br/>
			    <?
			    echo $arrayData['url_pic'] . "<br/>";
			}
		    }
		    ?>
		    <? if ($mode == "Edit_pic") { ?>
			<input type="file" name="url_pic" id="url_pic" value="<?= $arrayData['url_pic']; ?>"/> 
		    <? } ?>
		    <? if ($mode == "add_pic") { ?>
			<input type="file" multiple="multiple" name="url_pic[]" id="url_pic" value=""/>  <em>(* tối đã upload 6 file /  1 lần)</em>
		    <? } ?>
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Ghi chú</strong></td>
    	    <td>
		    <?php
//		    // Lay ve duong dan chinh cua server.
//		    $sBasePath = $_SERVER['PHP_SELF'];
//
//		    // Lay ve thu muc goc cho den _sample.
//		    $sBasePath = substr($sBasePath, 0, strpos($sBasePath, "run"));
//		    //echo "sBasePath = $sBasePath";
//		    $sBasePath = $sBasePath . "fckeditor/";
//		    $oFCKeditor = new FCKeditor('noi_dung');
//		    $oFCKeditor->BasePath = $sBasePath;
//		    $oFCKeditor->Width = '100%';
//		    $oFCKeditor->Height = '400';
//		    $oFCKeditor->Value = $arrayData["noi_dung"];
//		    $oFCKeditor->Create();
		    ?>
    		<textarea style="width: 400px; height: 150px" name="notes_pic" id="notes_pic"><?= $arrayData['notes_pic']; ?></textarea>
    	    </td>
    	</tr>
    	<tr>
    	    <td colspan="2">
    		<div style="float: right">
    		    <input type="reset" name="reset"  value="Nhập lại"/>
    		    <input type="submit" name="Submit" value="<?= $strButton ?>"/>
    		    <input type="button" name="Back" value="Quay lại" onclick="goBack();"/>
    		</div>
    	    </td>
    	</tr>
        </table>
    </form>
    <?
}

function gallerys_type($parent_id, $level, $id_nhom) {
    global $db;
    $objGallery = new MD_Gallery($db);
    $where = "parent_id = '$parent_id'";
    $order = "";
    $limit = "";
    $array = $objGallery->get_gallery_type_by_Where($where, $order, $limit);
    foreach ($array as $value) {
	$id = $value['id'];
	$selected = "";
	if ($id_nhom == $id) {
	    $selected = "Selected";
	}
	echo '<option ' . $selected . ' value="' . $id . '">' . str_repeat('- - ', $level) . $value['gallery_type_name'] . '</option>';
	gallerys_type($id, $level + 1, $id_nhom);
    }
}
?>
